//
//  LevelCompleteLayer.m
//  SpeedTap
//
//  Created by Chi Ho Chiu on 17/8/11.
//  Copyright 2011 Individual. All rights reserved.
//

#import "LevelCompleteLayer.h"
#import "GameManager.h"

@implementation LevelCompleteLayer
@synthesize delegate;

-(id) init
{
    if( (self = [super init]) )
    {
        CGSize winSize = [[CCDirector sharedDirector] winSize];
        
        CCLabelBMFont *label = [CCLabelBMFont labelWithString:@"Level Completed" fntFile:@"Dakota_white_32.fnt"];
        label.position = ccp(winSize.width/2, winSize.height/2);
        [self addChild:label];
        
        CCLabelBMFont *continueFont = [CCLabelBMFont labelWithString:@"Continue" fntFile:@"Dakota_white_24.fnt"];
        CCMenuItem *continueItem = [CCMenuItemLabel itemWithLabel:continueFont target:self selector:@selector(onMenuItemClicked:)];
        [continueItem setTag:kLEVEL_COMPLETE_TAG_CONTINUE];
        [continueItem setAnchorPoint:ccp(1,1)];
        
        CCLabelBMFont *retryFont = [CCLabelBMFont labelWithString:@"Retry" fntFile:@"Dakota_white_24.fnt"];
        CCMenuItem *retryItem = [CCMenuItemLabel itemWithLabel:retryFont target:self selector:@selector(onMenuItemClicked:)];
        [retryItem setTag:kLEVEL_COMPLETE_TAG_RETRY];
        [retryItem setAnchorPoint:ccp(1,1)];
        
        CCLabelBMFont *exitFont = [CCLabelBMFont labelWithString:@"Back to Menu" fntFile:@"Dakota_white_24.fnt"];
        CCMenuItem *exitItem = [CCMenuItemLabel itemWithLabel:exitFont target:self selector:@selector(onMenuItemClicked:)];
        [exitItem setTag:kLEVEL_COMPLETE_TAG_EXIT];
        [exitItem setAnchorPoint:ccp(1,1)];
        
        CCMenu *menu = [CCMenu menuWithItems:continueItem, retryItem, exitItem, nil];
        [menu alignItemsVertically];
        
        int menuItemsHeight = [continueItem contentSize].height + [retryItem contentSize].height + [exitItem contentSize].height;
        [menu setPosition: ccp( winSize.width, menuItemsHeight)];
        
        [self addChild:menu];
    
    }
    
    return self;
}

-(void) dealloc
{
    [delegate release];
    [super dealloc];
}
                 
-(void) onMenuItemClicked:(CCMenuItem *)menuItem
{
    switch (menuItem.tag) {
        case kLEVEL_COMPLETE_TAG_CONTINUE:
            [delegate onContinueItemClicked];
            break;
        case kLEVEL_COMPLETE_TAG_RETRY:
            [delegate onRetryItemClicked];
            break;
        case kLEVEL_COMPLETE_TAG_EXIT:
            [delegate onExitItemClicked];
            break;
        default:
            break;
    }
}

@end
  